package com.danciyixue.boot.client.unitTestRecord.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.danciyixue.boot.common.result.PageResult;
import com.danciyixue.boot.common.result.Result;
import com.danciyixue.boot.dcyx.model.form.UnitTestRecordsForm;
import com.danciyixue.boot.dcyx.model.query.UnitTestRecordsQuery;
import com.danciyixue.boot.dcyx.model.vo.UnitTestRecordsVO;
import com.danciyixue.boot.dcyx.service.UnitTestRecordsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 客户端单元测试记录控制器
 */
@Tag(name = "13. 单元测试记录", description = "单元测试记录")
@RestController
@RequestMapping("/api/client/v1/unit-test-record")
@RequiredArgsConstructor
public class DcyxUnitTestRecordController {

    private final UnitTestRecordsService unitTestRecordsService;

    /**
     * 获取单元测试记录数据
     */
    @Operation(summary = "单元测试记录分页列表")
    @GetMapping("/page")
    public PageResult<UnitTestRecordsVO> page(UnitTestRecordsQuery queryParams) {
        IPage<UnitTestRecordsVO> page = unitTestRecordsService.getUnitTestRecordsPage(queryParams);
        return PageResult.success(page);
    }

    @Operation(summary = "新增单元测试记录")
    @PostMapping
    public Result<Void> saveUnitTestRecords(@RequestBody @Valid UnitTestRecordsForm formData ) {
        boolean result = unitTestRecordsService.saveUnitTestRecords(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取单元测试记录表单数据")
    @GetMapping("/{id}/form")
    public Result<UnitTestRecordsForm> getUnitTestRecordsForm(
            @Parameter(description = "单元测试记录ID") @PathVariable Long id
    ) {
        UnitTestRecordsForm formData = unitTestRecordsService.getUnitTestRecordsFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改单元测试记录")
    @PutMapping(value = "/{id}")
    public Result<Void> updateUnitTestRecords(
            @Parameter(description = "单元测试记录ID") @PathVariable Long id,
            @RequestBody @Validated UnitTestRecordsForm formData
    ) {
        boolean result = unitTestRecordsService.updateUnitTestRecords(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除单元测试记录")
    @DeleteMapping("/{ids}")
    public Result<Void> deleteUnitTestRecordss(
            @Parameter(description = "单元测试记录ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = unitTestRecordsService.deleteUnitTestRecordss(ids);
        return Result.judge(result);
    }
} 